﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WIKID.Common;
using WIKID.Model;

namespace WIKID.View
{
    public partial class MainPanelView : UserControl
    {
        private bool scheduleStatus = false;
        private bool infoStatus = false;

        private int scheduleLabelTop = 25;

        public MainPanelView()
        {
            InitializeComponent();
        }

        private void btnInfo_Click(object sender, EventArgs e)
        {
            scheduleStatus = pnlSchedule.Visible = false;
            infoStatus = pnlInfo.Visible = !infoStatus;
        }

        private void btnSchedule_Click(object sender, EventArgs e)
        {
            infoStatus = pnlInfo.Visible = false;
            scheduleStatus = pnlSchedule.Visible = !scheduleStatus;
        }

        private void btnLogout_Click(object sender, EventArgs e)
        {
            frmMain.current.Close();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainPanelView_Load(object sender, EventArgs e)
        {
            if (!DesignMode)
            {
                DateTime now = DateTime.Now;
                AccountModel accountModel = new AccountModel();
                toolTip1.SetToolTip(btnInfo, "Info");
                toolTip1.SetToolTip(btnSchedule, "Schedule");
                toolTip1.SetToolTip(btnLogout, "Logout");
                frmMain mainForm = frmMain.current;
                if (mainForm.accountModel != null)
                {
                    accountModel = mainForm.accountModel;
                }
                btnInfo.BackgroundImage = Image.FromFile(accountModel.AccPic);
                lblAccountName.Text = accountModel.AccName;
                lblAge.Text += accountModel.AccAge.ToString();
                foreach (ScheduleModel schedule in accountModel.Schedules)
                {
                    if (DateTime.Compare(now, schedule.EndDateTime) <= 0)
                    {
                        CreateLabelSchedule(schedule);
                    }
                }
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="schedule"></param>
        private void CreateLabelSchedule(ScheduleModel schedule)
        {
            Label lblLecture = new Label();
            Label lblStartDateTime = new Label();
            Label lblEndDateTime = new Label();
            lblLecture.Location = new Point(10, scheduleLabelTop);
            lblStartDateTime.Location = new Point(150, scheduleLabelTop);
            lblEndDateTime.Location = new Point(320, scheduleLabelTop);
            lblLecture.AutoSize = true;
            lblStartDateTime.AutoSize = true;
            lblEndDateTime.AutoSize = true;
            lblLecture.Font = new Font(FontFamily.GenericSansSerif, 10f);
            lblStartDateTime.Font = new Font(FontFamily.GenericSansSerif, 10f);
            lblEndDateTime.Font = new Font(FontFamily.GenericSansSerif, 10f);
            lblLecture.ForeColor = Color.White;
            lblStartDateTime.ForeColor = Color.White;
            lblEndDateTime.ForeColor = Color.White;
            lblLecture.Text = "Lecture " + schedule.LectureId;
            lblStartDateTime.Text = schedule.StartDateTime.ToString("dd/MM/yyyy hh:mm:ss");
            lblEndDateTime.Text = schedule.EndDateTime.ToString("dd/MM/yyyy hh:mm:ss");
            pnlSchedule.Controls.Add(lblLecture);
            pnlSchedule.Controls.Add(lblStartDateTime);
            pnlSchedule.Controls.Add(lblEndDateTime);
            this.scheduleLabelTop += 20;
        }
    }
}
